/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects.encrypters;

import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.SecretKey;

import org.latestbit.smartobjects.io.ResizableByteBuffer;

/**
 * Interface provides access to all methods for symmetric encryption processing
 * @author abdulla-a
 *
 */
public interface ISymmetricDataEncrypter extends IDataEncrypter {

	/**
	 * Init algorithm with new symmetric key
	 * @param key Secret key for symmetric algorithm
	 * @throws InvalidKeyException
	 * @throws InvalidKeySpecException
	 */
	public void initCipher( SecretKey key ) throws InvalidKeyException, InvalidKeySpecException;
	
	/**
	 * Generate a new key for this symmetric implementation 
	 * @return A new secret key
	 * @throws GeneralSecurityException
	 */
	public SecretKey generateSecret ( ) throws GeneralSecurityException;

	/**
	 * Decode serialized form of secret key from byte buffer
	 * @param buffer input byte buffer
	 * @return Secret key
	 * @throws InvalidKeySpecException
	 * @throws NoSuchAlgorithmException
	 */
	public SecretKey decodeSecretKey(ByteBuffer buffer) throws InvalidKeySpecException, NoSuchAlgorithmException;
	
	/**
	 * Encode secret key to serialized form to output byte buffer
	 * @param key Input key
	 * @param buffer Output byte buffer
	 */
	public void encodeSecretKey( SecretKey key, ResizableByteBuffer buffer );
}
